<?php
//新增换行
function get_crlf()
{
    if (stristr($_SERVER['HTTP_USER_AGENT'], 'Win'))
    {
        $the_crlf = '\r\n';
    }
    elseif (stristr($_SERVER['HTTP_USER_AGENT'], 'Mac'))
    {
        $the_crlf = '\r'; // for old MAC OS
    }
    else
    {
        $the_crlf = '\n';
    }
    return $the_crlf;
}
//ini_set("max_execution_time","60");
set_time_limit(60);
function make_seed(){//播下随机数种子
   list($usec,$sec)=explode(" ",microtime());
   return (float)$sec+((float)$usec*100000);
}
//srand(make_seed());
function proce_exec_time(){
     list($sec,$usec)=explode(" ",microtime());
	 return ((float)$sec+(float)$usec);
}
//批量转换文件编码，有点问题,轻易不要使用,可以用editplus中批量修改编码
function file_convert($dir,$out_charset="UTF-8"){
   if(!is_dir($dir)) return false;
   $dir=dir($dir);
   while(false!==($filename=$dir->read())){
        if($filename=="."||$filename=="..")continue;
		if(is_file($dir."/".$filename)){//是文件
		     $content=file_get_contents($dir."/".$filename);
			 $org_encode=mb_detect_encoding($content,"ASCII,UTF-8");
			 if(function_exists("mb_convert_encoding")){
			      $content=mb_convert_encoding($content,$out_charset,$org_encode);
			 }else{
			     $content=iconv($org_encode,$out_charset,$content);
			 }
			 chmod($dir."/".$filename,0777);
			 unlink($dir."/".$filename);
			 if($fp=fopen($dir."/".$filename,"wb+")){
			       flock($fp,LOCK_EX);
				   fwrite($fp,$content);
				   flock($fp,LOCK_UN);
				   fclose($fp);
			 }
			 $now_encode=mb_detect_encoding(file_get_contents($dir."/".$filename));
			 if($now_encode==$org_encode) 
			     echo "对不起,".$dir."/".$filename."转码失败";
			 else
			     echo "恭喜你,".$dir."/".$filename."转码成功";
			 echo "<br>";
		}elseif(is_dir($dir."/".$filename)){
              file_convert($dir."/".$filename,$out_charset);		
		}else{
		    echo "对不起,".$dir."/".$filename."不是有效的文件";
		}
   }
}
function unescape($str){
    $ret = '';
    $len = strlen($str);
    for ($i = 0; $i < $len; $i++){
          if ($str[$i] == '%' && $str[$i+1] == 'u'){
                   $val = hexdec(substr($str, $i+2, 4));
                   if ($val < 0x7f){
				      $ret .= chr($val);
				   }else if($val < 0x800){
				       $ret .= chr(0xc0|($val>>6)).chr(0x80|($val&0x3f));
				   }else{
				      $ret .= chr(0xe0|($val>>12)).chr(0x80|(($val>>6)&0x3f)).chr(0x80|($val&0x3f));
				   }
                   $i += 5;
           }else if ($str[$i] == '%'){
                 $ret .= urldecode(substr($str, $i, 3));
                 $i += 2;
           }else {
		        $ret .= $str[$i];
		   }
     }
     return $ret;
}
function escape($str){
         $sublen=strlen($str);
         $retrunString="";
         for ($i=0;$i<$sublen;$i++){
                  if(ord($str[$i])>=127){
                           $tmpString=bin2hex(iconv("gb2312","ucs-2",substr($str,$i,2)));
                           //$tmpString=substr($tmpString,2,2).substr($tmpString,0,2);window下可能要打开此项
                           $retrunString.="%u".$tmpString;
                           $i++;
                  } else {
                           $retrunString.="%".dechex(ord($str[$i]));
                  }
         }
         return $retrunString;
}
//后台访问规范
function check_do_per(){
//   $http_refer=$_SERVER['HTTP_REFERER'];
//   if(empty($http_refer)){
//      alert('网站后台，不允许直接输入网址访问');
//   }
//   else{
//      $server_port=$_SERVER['SERVER_PORT'];
//	  $s_url="http://".$_SERVER['SERVER_NAME'].":".$server_port;
//	  $c_url_arr=parse_url($http_refer);//分析网址
//	  $c_url="http://".$c_url_arr["host"].":".$c_url_arr["port"];
//      if(strcmp($s_url,$c_url))   alert("网站后台，不允许从外部连接访问");
//	  
//   }
}
//安全处理客户端数据
//@param $data  string one_array  two_array .....
//@param $mode 模式  addslashes  js   html   例 1  1  1 转义 过滤js 过滤html 默认模式为不转义 过滤js,html  第一个参数如果为2,不做任何操作 兼容thinkphp 中使用$model->create();
function safedata(&$data,$model="011"){
	//先trim_deep
	trim_deep($data);
	$model_arr=preg_split('//',$model,-1,PREG_SPLIT_NO_EMPTY);//获取模式数组
    if($model_arr[0]==0){//取消转义
		stripslashes_deep($data);
	}elseif($model_arr[0]==1){//转义
		addslashes_deep($data);
	}
	if($model_arr[1])js_deep($data);
	if($model_arr[2])html_deep($data);
}
function trim_deep(&$data){
    if(is_string($data)){
	   $data=trim($data);	
	}elseif(is_array($data)){
	   	foreach($data as $k=>$v){
		   trim_deep($v);
		   $data[$k]=$v;
		}
	}
}
function addslashes_deep(&$data){
    if(is_string($data)){
	   if(!get_magic_quotes_gpc())$data=addslashes($data);	
	}elseif(is_array($data)){
	   	foreach($data as $k=>$v){
		   addslashes_deep($v);
		   $data[$k]=$v;
		}
	}
}
function stripslashes_deep(&$data){
    if(is_string($data)){
	   if(get_magic_quotes_gpc())$data=stripslashes($data);	
	}elseif(is_array($data)){
	   	foreach($data as $k=>$v){
		   stripslashes_deep($v);
		   $data[$k]=$v;
		}
	}
}
function js_deep(&$data){
     $pattern= array("'<script[^>]*?>.*?</script>'si","'&lt;script[^&gt;]*?&gt;.*?&lt;/script&gt;'si");
     $replace = array("",""); 
	 if(is_string($data)){
		 $data=preg_replace($pattern,$replace,$data);
	 }elseif(is_array($data)){
		 foreach($data as $k=>$v){
			 js_deep($v);
			 $data[$k]=$v;
		 }
	 }
}
function html_deep(&$data){
	 $pattern= array(
	   "'<[\/\!]*?[^<>]*?>'si",//去掉 HTML 标记
       "'&(quot|#34);'i",// 替换 HTML 实体
       "'&(amp|#38);'i",
       "'&(lt|#60);'i",
       "'&(gt|#62);'i",
       "'&(nbsp|#160);'i",
       "'&(iexcl|#161);'i",
       "'&(cent|#162);'i",
       "'&(pound|#163);'i",
       "'&(copy|#169);'i",
	 ); 
     $replace = array(
	   "",
       "\"",
       "&",
       "<",
       ">",
       " ",
       chr(161),
       chr(162),
       chr(163),
       chr(169),
	 ); 
	 if(is_string($data)){
		 $data=preg_replace($pattern,$replace,$data);
	 }elseif(is_array($data)){
		 foreach($data as $k=>$v){
			 html_deep($v);
			 $data[$k]=$v;
		 }
	 }
}
function saferequest($str,$model="111"){ //表单数据输入过滤  针对单个变量
    header("Content-type:text/html;charset=utf-8");
	if(empty($str)) return 0;
	safedata($str,$model);
	return $str;
}
//also checkpost 兼容
function checkform($model="011"){
    header("Content-type:text/html;charset=utf-8");
	safedata($_POST,$model);
}
/**
 * @desc 过滤post提交
 * @author lijianwei
 * @return  处理好的$_POST
 */
function checkpost($model="011"){
    header("Content-type:text/html;charset=utf-8");
	safedata($_POST,$model);
}
/**
 * @desc  过滤get提交
 * @author lijianwei
 * @return 处理好的$_get
 */
function checkget($model="011"){
    header("Content-type:text/html;charset=utf-8");
	safedata($_GET,$model);
}
/*
作用：显示级联项
参数：$item_arr  array(
            array(父类别1的名称=>父类别1的值,array(子类别1的名称=>子类别1的值,子类别2的名称=>子类别2的值,,,,,,),
			父类别2的名称=>,,,,,,
			2=>,,,,
           );
返回：下拉菜单
*/
function show_cascade_item($item_arr,$select_value=null,$space=null){//显示级联项
     if(!is_array($item_arr)) return 0;
	 foreach($item_arr as $k=>$v){
	    if(is_array($v)){
        foreach($v as $n=>$m){
		    $p=$space;
			$c=$space."&nbsp;&nbsp;";
		    if(!is_array($m)){//说明父类别
			    if($m==$select_value&&!empty($select_value)) $select="selected=selected";
			    $str.="<option value='{$m}' {$select}>{$p}┣{$n}</option>";
				unset($select);
			}else{//说明是子类别
			    foreach($m as $x=>$y){
				    if(!is_array($y)){
						if($y==$select_value&&!empty($select_value)) $select="selected=selected";
						$str.="<option value='{$y}' {$select}>{$c}┣{$x}</option>";
						unset($select);  
					}else{
					   $call_para[0]=$y;
					   $str.=show_cascade_item($call_para,$select_value,$c);
					   unset($call_para);
					}
				}
			}
		}
		}else{
		   if($v==$select_value&&!empty($select_value)) $select="selected=selected";
		   $str.="<option value='{$v}' {$select}>┣{$k}</option>"; 
		   unset($select); 
		}
	 }
	 return $str;
}

function create_cascade_item($modelname,$parid_value=0,$show_field="",$condition=null,$parid_field='parid',$key_field='id'){
     if(empty($modelname)) return 0;
	 if(empty($parid_field)) return 0;
     $model=M($modelname);
	 if(!empty($condition)){
	     $par=$model->where("$parid_field=$parid_value and $condition")->field("$key_field,$parid_field,$show_field")->order("sequence desc")->findAll();
	 }else{
	    $par=$model->where("$parid_field=$parid_value")->field("$key_field,$parid_field,$show_field")->order("sequence desc")->findAll();
	 }
	 $res=array();
	 foreach($par as $k=>$v){//浙江  黑龙江
	     $par_show=$v[$show_field];
		 $par_value=$v[$key_field];
		 $id=$v[$key_field];
		 if(!empty($condition)){
		    $child=$model->where("$parid_field=$id and $condition")->field("$key_field,$parid_field,$show_field")->order("sequence desc")->findAll();
		 }else{
		    $child=$model->where("$parid_field=$id")->field("$key_field,$parid_field,$show_field")->order("sequence desc")->findAll();
		 }
	     if(!empty($child)){
		     $p=array($par_show=>$par_value);
		     $c=array();
		     foreach($child as $x=>$y){ //杭州 金华
			       $child_show=$y[$show_field];
				   $child_value=$y[$key_field];
			       $child_id=$y[$key_field];
				   if(!empty($condition)){
				       $child_child=$model->where("$parid_field=$child_id and $condition")->field("$key_field,$parid_field,$show_field")->order("sequence desc")->findAll();
				   }else{
				       $child_child=$model->where("$parid_field=$child_id")->field("$key_field,$parid_field,$show_field")->order("sequence desc")->findAll();
				   }
				   if(!empty($child_child)){
				      $c_c=array($child_show=>$child_value);
				      $return_arr=create_cascade_item($modelname,$child_id,$show_field,$condition,$parid_field,$key_field);
					  array_push($c_c,$return_arr);
					  array_push($c,$c_c);
					  unset($c_c);
					  unset($return_arr);
				   }else{
				      $c[$child_show]=$child_value;
				   }
			 }
             array_push($p,$c);
			 array_push($res,$p);
			 unset($c);
			 unset($p);
		 }else{
		     $res[$par_show]=$par_value;
		 }
	 }
	 return $res;

}

function checkmembername(){//检测会员名
    $membername=saferequest($_POST["member_name"]);
	if(strlen($membername)<4||strlen($membername)>16) return false;
	if(preg_match("/[^a-zA-Z0-9_]+/i",$membername)) return false;
}

function checkpwd(){//检测密码
   $pwd=saferequest($_POST["member_pwd"]);
   if(strlen($pwd)<6||strlen($pwd)>20) return false;
   if(preg_match("/[^a-zA-Z0-9_]+/",$pwd)) return false;
}

function alert($str,$url=null){//$url 不访问过去的网页，在网址后面加个 "/".rand()
  if(empty($str)) return 0;
  header("Content-type:text/html;charset=utf-8");
  if(empty($url))
    echo "<script language='javascript'>alert(\"$str\");history.go(-1);</script>";
 else
    echo "<script language='javascript'>alert(\"$str\");location.href='$url';</script>"; 
 exit;
}

function array2object($arr=array()){// 数组转对象
    if(!is_array($arr)||empty($arr)) return 0;
	$s=new stdClass;
	foreach($arr as $k=>$v){
	   $s->$k=$v;
	}
	return $s;
}

function object2array($obj){//对象转数组
     if(!is_object($obj)||empty($obj)) return 0;
	 $arr=get_object_vars($obj);
	 return $arr;
}
//$data 要导出的数据  把数据导出到excel
//格式 array(array("商品编码","尺码","颜色","类别","地区","原价(元)"),array('第一行的数据'),array('第二行的数据');
//数据编码 gbk
function export2excel($data=array()){
   if(empty($data)) return 0;
   $filename=date("Y-m-d").".xls";
   header("Content-type:application/vnd.ms-excel");
   header("Content-Disposition:filename=$filename");
   $field=array_shift($data);
   foreach($field as $v){
      echo $v."\t";
   }
   echo "\n";
   foreach($data as $k=>$v){
      foreach($v as $n){
	     echo $n."\t";
	  }
	  echo "\n";
   }   
}
//数组转码  gbk utf-8
function arr_iconv($arr=array(),$in_charset='utf-8',$out_charset='gb2312'){
   if(empty($in_charset)||empty($out_charset)||empty($arr)) return 0;
   foreach($arr as $k=>$v){
      if(is_array($v)){
	    $arr[$k]=arr_iconv($v,$in_charset,$out_charset);
	  }else{
	    $arr[$k]=iconv($in_charset,$out_charset,$v);
	  }
   }
   return $arr;
}

//生成缩略图
//$picpath 图片路径
//$savepath 保存路径 
//$del 是否删除
function thumb($picpath){ //460 *460  51*68  30*40  150*200  88*120
    if(!is_file($picpath)) alert('不是正常的文件名');
	$pic_info=getimagesize($picpath);
	$width=$pic_info[0];
	$height=$pic_info[1];
	Vendor("LJW.Inc_File");
	import("ORG.Cons");
	$myfile=new Inc_File(Cons::$websetup["max_pic_size"]);
	if($width<460&&$height<460){
	   //150*200
	   $small_file1=encode_spic($picpath,150);
	   $w=$width/150;
	   $h=$height/200;
	   if($w>$h){
	       $newwidth=$width/$w;
		   $newheight=ceil($height/$w);
	   }else{
	       $newwidth=ceil($width/$h);
		   $newheight=$height/$h;
	   }
	   $myfile->image_resize($picpath,$newwidth,$newheight,$small_file1);
	   //68*70
	   $small_file2=encode_spic($picpath,68);
	   $w=$width/51;
	   $h=$height/68;
	   if($w>$h){
	       $newwidth=$width/$w;
		   $newheight=ceil($height/$w);
	   }else{
	       $newwidth=ceil($width/$h);
		   $newheight=$height/$h;
	   }
	   $myfile->image_resize($picpath,$newwidth,$newheight,$small_file2);
	   //30*40
	   $small_file3=encode_spic($picpath,30);
	   $w=$width/30;
	   $h=$height/40;
	   if($w>$h){
	       $newwidth=$width/$w;
		   $newheight=ceil($height/$w);
	   }else{
	       $newwidth=ceil($width/$h);
		   $newheight=$height/$h;
	   }
	   $myfile->image_resize($picpath,$newwidth,$newheight,$small_file3);
	   //88*120
	   $small_file4=encode_spic($picpath,88);
	   $w=$width/88;
	   $h=$height/120;
	   if($w>$h){
	       $newwidth=$width/$w;
		   $newheight=ceil($height/$w);
	   }else{
	       $newwidth=ceil($width/$h);
		   $newheight=$height/$h;
	   }
	   $myfile->image_resize($picpath,$newwidth,$newheight,$small_file4);
	   
	   $newfile=encode_spic($picpath,'b');
	   $myfile->copyfile($picpath,$newfile);
	   return $picpath;
	}else{
	   //150*200
	   $small_file1=encode_spic($picpath,150);
	   $w=$width/150;
	   $h=$height/200;
	   if($w>$h){
	       $newwidth=$width/$w;
		   $newheight=ceil($height/$w);
	   }else{
	       $newwidth=ceil($width/$h);
		   $newheight=$height/$h;
	   }
	   $myfile->image_resize($picpath,$newwidth,$newheight,$small_file1);
	   //68*70
	   $small_file2=encode_spic($picpath,68);
	   $w=$width/51;
	   $h=$height/68;
	   if($w>$h){
	       $newwidth=$width/$w;
		   $newheight=ceil($height/$w);
	   }else{
	       $newwidth=ceil($width/$h);
		   $newheight=$height/$h;
	   }
	   $myfile->image_resize($picpath,$newwidth,$newheight,$small_file2);
	   //30*40
	   $small_file3=encode_spic($picpath,30);
	   $w=$width/30;
	   $h=$height/40;
	   if($w>$h){
	       $newwidth=$width/$w;
		   $newheight=ceil($height/$w);
	   }else{
	       $newwidth=ceil($width/$h);
		   $newheight=$height/$h;
	   }
	   $myfile->image_resize($picpath,$newwidth,$newheight,$small_file3);
	   //88*120
	   $small_file4=encode_spic($picpath,88);
	   $w=$width/88;
	   $h=$height/120;
	   if($w>$h){
	       $newwidth=$width/$w;
		   $newheight=ceil($height/$w);
	   }else{
	       $newwidth=ceil($width/$h);
		   $newheight=$height/$h;
	   }
	   $myfile->image_resize($picpath,$newwidth,$newheight,$small_file4);
	   
	   $newfile=encode_spic($picpath,'b');
	   $myfile->copyfile($picpath,$newfile);
	   
	   $newfile=encode_spic($picpath,'n');
	   $w=$width/460;
	   $h=$height/460;
	   if($w>$h){
	       $newwidth=$width/$w;
		   $newheight=ceil($height/$w);
	   }else{
	       $newwidth=ceil($width/$h);
		   $newheight=$height/$h;
	   }
	   $myfile->image_resize($picpath,$newwidth,$newheight,$newfile);
	   $myfile->DeleteFile($picpath);
	   $myfile->RenameFile($newfile,$picpath);
	   return $picpath;
	}
}

function encode_spic($picpath,$label){//对上传的图片做一些处理
   if(empty($label)) return $picpath;
   $picarr=explode("/",$picpath);
   $filename=array_pop($picarr);
   $path=implode("/",$picarr);
   
   $filearr=explode(".",$filename);
   $newfilename=$filearr[0]."_".$label.".".$filearr[1];
   
   $newpath=$path."/".$newfilename;
   return $newpath;
}
/*
utf-8,gb2312截取字符 汉字
$string  字符
$sublen  个数
$is_dot 是否加省略号
$start 开始位置 默认为0
$code 编码
返回:截取的字符
*/
function cut_str($string,$sublen,$is_dot=true,$start=0,$code= 'UTF-8'){ 
     if($code == 'UTF-8'){ 
        $pa = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/"; 
        preg_match_all($pa, $string, $t_string); 
        if((count($t_string[0]) - $start > $sublen)&&$is_dot) return join('', array_slice($t_string[0], $start, $sublen))."..."; 
        return join('', array_slice($t_string[0], $start, $sublen)); 
     }else{ 
        $start = $start*2; 
        $sublen = $sublen*2; 
        $strlen = strlen($string); 
        $tmpstr = ''; 
 
        for($i=0; $i< $strlen; $i++){ 
            if($i>=$start && $i< ($start+$sublen)){ 
                if(ord(substr($string, $i, 1))>129){ 
                    $tmpstr.= substr($string, $i, 2); 
                }else{ 
                    $tmpstr.= substr($string, $i, 1); 
                } 
            } 
            if(ord(substr($string, $i, 1))>129) $i++; 
        } 
        if((strlen($tmpstr)< $strlen)&&$is_dot) $tmpstr.= "..."; 
        return $tmpstr; 
    } 
} 
function is_2_array($arr){//是否为二维数组
     if(!is_array($arr)) return false;
     foreach($arr as $k=>$v){
	    if(is_array($v)) return true;
	 }
	 return false;
}

//根据类别id求出所有子类和自己
//$condition 条件 类似于 col_id=$col_id
//返回 array
function typeid2child($typeid=0,$modelname="sysclass",$condition){
   if(empty($typeid)) return 0;
   $model=M($modelname);
   if(!empty($condition)){
	  $arr=$model->where("parpath like '%,$typeid' or parpath like '%,$typeid,%'")->field("id")->findAll();  
   }else{
	  $arr=$model->where("parpath like '%,$typeid' or parpath like '%,$typeid,%' and $condition")->field("id")->findAll();  
   }
   if(empty($arr)) return array($typeid);
   $list=array();
   foreach($arr as $v){
      array_push($list,$v["id"]);
   };
   array_push($list,$typeid);
   return $list;
}
//根据类别id求出所有父类别和自己
//$condition  类似于col_id=$col_id
//返回array
function typeid2par($typeid=0,$modelname,$condition){
    if(empty($typeid)) return 0;
	$model=M($modelname);
	if(empty($condition)){
		$parpath=$model->where("id=$typeid")->getField("parpath");
	}else{
		$parpath=$model->where("id=$typeid and $condition")->getField("parpath");
	}
	$pararr=explode(",",$parpath);
	array_shift($pararr);
	array_push($pararr,$typeid);
	return $pararr;
}
//根据类别求出类别字符串 首页>>类别一>>类别二
//$typeid 类别id
//$prefix 前缀
//$modelname
//$str_field="class_name";
//$url 连接的网址
//notice: 要确保 $modelname中有parid 和 parpath 字段 
//$sep 分隔符
function typestr($typeid,$modelname,$condition,$str_field,$url,$sep="&nbsp;>>&nbsp;",$prefix=null){
   $arr=typeid2par($typeid,$modelname,$condition);
   $model=M($modelname);
   $arr1=$prefix?array($prefix):array();
   foreach($arr as $k=>$v){
      $str=$model->where("id=$v")->getField($str_field);
	  if(!empty($url)){
	    $url_str=$url.$v;
	    $str="<a href='$url_str'>$str</a>";
	  }
	  array_push($arr1,$str);
   }
   return implode($sep,$arr1);
}
//获取客户端来源
function  get_ph_address(){
    import("ORG.Net.IpLocation");
    $myIp=new IpLocation("QQWry.Dat");
	$ip=$myIp->get_client_ip();
    $l=$myIp->getlocation($ip);
    $address=$l["country"];
	//需要转换一下编码
	return iconv("gb2312","utf-8",$address);
}
//获取客户端ip地址
function get_client_ip(){
   if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown"))
		 $ip = getenv("HTTP_CLIENT_IP");
   else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown"))
		 $ip = getenv("HTTP_X_FORWARDED_FOR");
   else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown"))
		 $ip = getenv("REMOTE_ADDR");
   else if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown"))
		 $ip = $_SERVER['REMOTE_ADDR'];
   else
		 $ip = "unknown";
   return($ip);
}
//判断是否为https协议请求
function getishttps(){
	if(isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == 'on')return true;
	return false;
}
//修正strip_taga 无法替换html实体
//使用 del_html_entity(strip_tags($html))
function del_html_entity($html){
	if(empty($html))return false;
	$html=html_entity_decode($html,ENT_QUOTES,"UTF-8");
	return trim($html);
}

//去除html代码 可以是字符串 一维数组  二维数据
function del_html_arr(&$data){
	if(is_string($data)){
         if(!get_magic_quotes_gpc())$data=addslashes($data);
	     $data=trim(strip_tags($data));
	}else{
	   foreach($data  as $key=>$value){
	     if(is_array($value)){
		   del_html($value);
		   $data[$key]=$value;
	     }else{
		   if(!get_magic_quotes_gpc())$value=addslashes($value);
	       $data[$key]=trim(strip_tags($value));
	     }
	  }
    }
}
//根据typeid求出所有子类  sysclass 表中
//$condition 类似于 col_id=$col_id;
function getchild($typeid,$condition){
	if(empty($typeid))return 0;
	if(empty($condition))return 0;
	
	$sysclass=M("sysclass");
	if(empty($condition)){
	   $child=$sysclass->where("parid=$typeid")->order("sequence desc")->findAll();
	}else{
	   $child=$sysclass->where("parid=$typeid and $condition")->order("sequence desc")->findAll();
	}
	if(!empty($child))return $child;
	return 0;
}
/**
 * @desc 获取网站网址  http://localhost:8000/qibu
 * @author lijianwei
 */
function server_url(){
   $pt=(isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == 'on')?"https://":"http://";
   $port=($_SERVER['SERVER_PORT']=="80")?"":":".$_SERVER["SERVER_PORT"];
   return $pt.$_SERVER['SERVER_NAME'].$port.__ROOT__;
}
/**
 * @desc 获取服务器网址  http://localhost:8000/
 * @author lijianwei
 */
function  web_url(){
   $pt=(isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == 'on')?"https://":"http://";
   $port=($_SERVER['SERVER_PORT']=="80")?"":":".$_SERVER["SERVER_PORT"];
   return $pt.$_SERVER['SERVER_NAME'].$port;
}
?>
